package io.terminus.lego.shinda.web.oauth2.endpoint

import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.terminus.lego.shinda.service.model.toDTO
import io.terminus.lego.shinda.service.service.UserService
import io.terminus.lego.shinda.web.controller.dto.UserDTO
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.security.core.Authentication
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

/**
 * Oauth2.0接口，获取用户信息
 * @author wangmeng
 * @date 2018/4/13
 */
@Api(value = "Endpoint-开放Oauth2.0接口", description = "client获取到access_token后访问UC的相关接口")
@RestController
@RequestMapping("/api/oauth")
class UserInfoEndpoint @Autowired constructor(val userService: UserService) {

    @ApiOperation(value = "获取用户信息")
    @GetMapping("me")
    fun me(authentication: Authentication): UserDTO? {
        return userService.findUserByUsername(authentication.name)?.toDTO()
    }

}